class="lines-num lines-num-old"> 238 238
 

+ 15 - 14
miniapp/qy_views.py

@@ -1,9 +1,9 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-import logging
4
-import requests
5 3
 import json
4
+import logging
6 5
 
6
+import requests
7 7
 from django.conf import settings
8 8
 from django.db import transaction
9 9
 from django_curtail_uuid import CurtailUUID
@@ -16,14 +16,15 @@ from pywe_storage import RedisStorage
16 16
 from TimeConvert import TimeConvert as tc
17 17
 
18 18
 from account.models import UserInfo
19
-from mch.models import SaleclerkInfo, DistributorInfo, MaintenancemanInfo
20
-from statistic.models import RegisterStatisticInfo
21
-from member.models import RightInfo
22 19
 from coupon.models import UserCouponInfo
20
+from mch.models import DistributorInfo, MaintenancemanInfo, SaleclerkInfo
21
+from member.models import RightInfo
22
+from statistic.models import RegisterStatisticInfo
23 23
 from utils.error.errno_utils import ProductBrandStatusCode, ProductDistributorStatusCode, UserStatusCode
24 24
 from utils.redis.connect import r
25 25
 from utils.redis.rprofile import set_profile_info
26 26
 
27
+
27 28
 WECHAT = settings.WECHAT
28 29
 logger = logging.getLogger('logit')
29 30
 
@@ -48,11 +49,11 @@ def qy_login_api(request):
48 49
 
49 50
     token = access_token(appid=appid, secret=secret, storage=RedisStorage(r))
50 51
 
51
-    userinfo = requests.post(url='https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token='+token+'&userid='+userid).text
52
+    userinfo = requests.post(url='https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=' + token + '&userid=' + userid).text
52 53
     userinfo = json.loads(userinfo)
53 54
 
54 55
     mobile = userinfo.get('mobile', '')
55
-    
56
+
56 57
     # Get or Create User
57 58
     user, created = UserInfo.objects.select_for_update().get_or_create(appid=appid, userid=userid)
58 59
 
@@ -83,14 +84,14 @@ def qy_login_api(request):
83 84
     if 122 in userinfo.get('department', []):
84 85
         maintenance, created = MaintenancemanInfo.objects.get_or_create(brand_id=brand_id, maintenance_phone=mobile, status=True)
85 86
         user.is_maintenance = True
86
-        
87
+
87 88
         if created:
88 89
             maintenance.maintenance_name = userinfo.get('name', '')
89 90
             maintenance.maintenance_sex = userinfo.get('gender', 0)
90 91
             maintenance.maintenance_phone = mobile
91 92
             maintenance.user_id = user.user_id
92 93
             maintenance.wx_userid = userid
93
-            maintenance.save()        
94
+            maintenance.save()
94 95
     else:
95 96
         user.is_maintenance = False
96 97
         # 销售员登录
@@ -99,9 +100,9 @@ def qy_login_api(request):
99 100
         if created:
100 101
             try:
101 102
                 distributor = DistributorInfo.objects.get(department_id__in=userinfo.get('department', []))
102
-            except:
103
+            except DistributorInfo.DoesNotExist:
103 104
                 return response(ProductDistributorStatusCode.DISTRIBUTOR_NOT_FOUND)
104
-            
105
+
105 106
             saleclerk.brand_id = brand_id
106 107
             saleclerk.distributor_id = distributor.distributor_id
107 108
             saleclerk.distributor_name = distributor.distributor_name
@@ -113,7 +114,7 @@ def qy_login_api(request):
113 114
             saleclerk.user_status = SaleclerkInfo.ACTIVATED
114 115
             saleclerk.is_auth = True
115 116
             saleclerk.save()
116
-          
117
+
117 118
     user.save()
118 119
 
119 120
     return response(200, 'Mini App Login Success', u'微信小程序登录成功', user.brand_qydata(brand_id=brand_id))
@@ -128,9 +129,9 @@ def query_userinfo(request):
128 129
 
129 130
     try:
130 131
         user = UserInfo.objects.get(memberusercardcode=memebercardcode, status=True)
131
-    except:
132
+    except UserInfo.DoesNotExist:
132 133
         return response(UserStatusCode.USER_NOT_FOUND)
133
-    
134
+
134 135
     # 维修人工费
135 136
     right = RightInfo.objects.get(right_id='X457xEV8KVxHQiTvhA7Dtf')
136 137
     coupons = UserCouponInfo.objects.filter(user_id=user.user_id, has_used=False, status=True)

+ 4 - 3
miniapp/views.py

@@ -14,8 +14,8 @@ from pywe_storage import RedisStorage
14 14
 from TimeConvert import TimeConvert as tc
15 15
 
16 16
 from account.models import UserInfo
17
-from statistic.models import RegisterStatisticInfo
18 17
 from mch.models import SaleclerkInfo
18
+from statistic.models import RegisterStatisticInfo
19 19
 from utils.error.errno_utils import ProductBrandStatusCode, UserStatusCode
20 20
 from utils.redis.connect import r
21 21
 from utils.redis.rprofile import set_profile_info
@@ -158,9 +158,10 @@ def mini_login_api(request):
158 158
         # 同步销售员手机号
159 159
         try:
160 160
             saleclerk = SaleclerkInfo.objects.get(unionid=unionid, is_auth=True, status=True)
161
+        except SaleclerkInfo.DoesNotExist:
162
+            saleclerk = None
163
+        if saleclerk:
161 164
             user.phone = saleclerk.clerk_phone
162
-        except:
163
-            pass
164 165
         user.unionid = unionid
165 166
     user.user_status = UserInfo.ACTIVATED
166 167
     user.signup_ip = client_ip(request)

+ 38 - 27
page/sale_views.py

@@ -17,10 +17,11 @@ from account.models import UserInfo
17 17
 from coupon.models import UserCouponInfo
18 18
 from integral.models import SaleclerkIntegralIncomeExpensesInfo, SaleclerkSubmitLogInfo
19 19
 from logs.models import MchInfoEncryptLogInfo
20
-from mch.models import BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, ModelInfo, SaleclerkInfo, MaintenancemanInfo
20
+from mch.models import (BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, MaintenancemanInfo, ModelInfo,
21
+                        SaleclerkInfo)
22
+from member.models import RightInfo
21 23
 from statistic.models import (DistributorSaleStatisticInfo, ModelSaleStatisticInfo, ProvinceSaleStatisticInfo,
22 24
                               SaleclerkSaleStatisticInfo, SaleStatisticInfo)
23
-from member.models import RightInfo
24 25
 from utils.error.errno_utils import (CouponStatusCode, ProductBrandStatusCode, ProductDistributorStatusCode,
25 26
                                      ProductMachineStatusCode, ProductModelStatusCode, SaleclerkStatusCode)
26 27
 
@@ -454,19 +455,26 @@ def clerk_query_coupon(request):
454 455
         user_coupon = UserCouponInfo.objects.get(user_coupon_id=user_coupon_id)
455 456
     except UserCouponInfo.DoesNotExist:
456 457
         return response(CouponStatusCode.COUPON_NOT_FOUND)
457
-    
458
+
458 459
     right_detail = ''
459 460
     if is_maintenance:
460 461
         try:
461
-            maintenance = MaintenancemanInfo.objects.get(brand_id=brand.brand_id, user_id=user.user_id,  status=True)
462
-            
463
-            # 维修人工费
462
+            maintenance = MaintenancemanInfo.objects.get(brand_id=brand.brand_id, user_id=user.user_id, status=True)
463
+        except MaintenancemanInfo.DoesNotExist:
464
+            return response(400001, 'MaintenancemanInfo Not Found', u'维修员不存在')
465
+
466
+        # 维修人工费
467
+        try:
464 468
             right = RightInfo.objects.get(right_id='X457xEV8KVxHQiTvhA7Dtf')
465
-            member = UserInfo.objects.get(user_id=user_coupon.user_id)
469
+        except RightInfo.DoesNotExist:
470
+            return response(400001, 'MaintenancemanInfo Not Found', u'维修员不存在')
466 471
 
467
-            right_detail = right.maintaindata(level=member.level)
468
-        except:
472
+        try:
473
+            member = UserInfo.objects.get(user_id=user_coupon.user_id)
474
+        except UserInfo.DoesNotExist:
469 475
             return response(400001, 'MaintenancemanInfo Not Found', u'维修员不存在')
476
+
477
+        right_detail = right.maintaindata(level=member.level)
470 478
     else:
471 479
         try:
472 480
             clerk = SaleclerkInfo.objects.get(brand_id=brand.brand_id, clerk_phone=user.phone, status=True)
@@ -503,40 +511,43 @@ def clerk_writeoff_coupon(request):
503 511
             brand = BrandInfo.objects.get(brand_id=brandID)
504 512
         except BrandInfo.DoesNotExist:
505 513
             return response(ProductBrandStatusCode.BRAND_NOT_FOUND)
506
-    
514
+
507 515
     try:
508 516
         user_coupon = UserCouponInfo.objects.get(user_coupon_id=user_coupon_id)
509
-        if user_coupon.has_used:
510
-            return response(CouponStatusCode.COUPON_HAS_USED)
511
-        elif user_coupon.is_coupon_admin_writeoff and not is_maintenance:
512
-            return response(CouponStatusCode.COUPON_PERMISSION_DENIED)
513
-        elif user_coupon.has_expired:
514
-            return response(CouponStatusCode.COUPON_EXPIRED)   
515 517
     except UserCouponInfo.DoesNotExist:
516 518
         return response(CouponStatusCode.COUPON_NOT_FOUND)
517
-    
519
+
520
+    if user_coupon.has_used:
521
+        return response(CouponStatusCode.COUPON_HAS_USED)
522
+    elif user_coupon.is_coupon_admin_writeoff and not is_maintenance:
523
+        return response(CouponStatusCode.COUPON_PERMISSION_DENIED)
524
+    elif user_coupon.has_expired:
525
+        return response(CouponStatusCode.COUPON_EXPIRED)
526
+
518 527
     user_coupon.has_used = True
519 528
     user_coupon.used_at = tc.utc_datetime()
520 529
 
521 530
     if is_maintenance:
522 531
         try:
523
-            maintenance = MaintenancemanInfo.objects.get(brand_id=brand.brand_id, user_id=user.user_id,  status=True)
524
-            user_coupon.admin_id = maintenance.maintenance_id
525
-            user_coupon.admin_name = maintenance.maintenance_name
526
-            user_coupon.save()
527
-        except:
532
+            maintenance = MaintenancemanInfo.objects.get(brand_id=brand.brand_id, user_id=user.user_id, status=True)
533
+        except MaintenancemanInfo.DoesNotExist:
528 534
             return response(400001, 'MaintenancemanInfo Not Found', u'维修员不存在')
535
+
536
+        user_coupon.admin_id = maintenance.maintenance_id
537
+        user_coupon.admin_name = maintenance.maintenance_name
538
+        user_coupon.save()
529 539
     else:
530 540
         try:
531 541
             clerk = SaleclerkInfo.objects.get(brand_id=brand.brand_id, clerk_phone=user.phone, status=True)
532
-            user_coupon.clerk_id = clerk.clerk_id
533
-            user_coupon.clerk_name = clerk.clerk_name
534
-            user_coupon.distributor_id = clerk.distributor_id
535
-            user_coupon.distributor_name = clerk.distributor_name
536
-            user_coupon.save()
537 542
         except SaleclerkInfo.DoesNotExist:
538 543
             return response(SaleclerkStatusCode.CLERK_NOT_FOUND)
539 544
 
545
+        user_coupon.clerk_id = clerk.clerk_id
546
+        user_coupon.clerk_name = clerk.clerk_name
547
+        user_coupon.distributor_id = clerk.distributor_id
548
+        user_coupon.distributor_name = clerk.distributor_name
549
+        user_coupon.save()
550
+
540 551
     return response(200, 'Write Off Coupon Success', u'劵核销成功')
541 552
 
542 553
 

+ 1 - 1
shells/views.py

@@ -3,8 +3,8 @@
3 3
 from django.conf import settings
4 4
 from django_redis_connector import connector
5 5
 from pywe_storage import RedisStorage
6
-
7 6
 from pywe_user import get_all_users
7
+
8 8
 from utils.redis.rkeys import SUBSCRIBE_USERINFO_LIST
9 9
 
10 10
 

:art: Update UserIntegralIncomeExpensesInfo · 7ba238c291 - Gogs: Go Git Service

:art: Update UserIntegralIncomeExpensesInfo

huangqimin001 3 years ago
parent
commit
7ba238c291

+ 4 - 3
account/admin.py

@@ -8,7 +8,7 @@ from mch.models import ConsumeInfoSubmitLogInfo
8 8
 
9 9
 
10 10
 class UserInfoAdmin(ChangeOnlyModelAdmin, admin.ModelAdmin):
11
-    list_display = ('user_id', 'nickname', 'phone', 'appid', 'unionid', 'openid', 'openid_miniapp', 'location', 'balance', 'integral', 'freeze_integral', 'user_status', 'test_user', 'integral', 'freeze_integral', 'shots_num', 'level', 'coupon_expire_at', 'is_maintenance', 'status', 'created_at', 'updated_at')
11
+    list_display = ('user_id', 'nickname', 'phone', 'appid', 'unionid', 'openid', 'openid_miniapp', 'location', 'balance', 'user_status', 'test_user', 'integral', 'freeze_integral', 'shots_num', 'level', 'coupon_expire_at', 'is_maintenance', 'status', 'created_at', 'updated_at')
12 12
     list_filter = ('user_from', 'appid', 'subscribe', 'has_membercard', 'test_user', 'is_maintenance', 'sex', 'user_status', 'status', 'code_version', 'new_subscribe', 'created_at', 'integral')
13 13
     readonly_fields = ('user_id', )
14 14
     search_fields = ('user_id', 'username', 'unionid', 'openid', 'openid_miniapp', 'name', 'phone', 'location', 'memberusercardcode')
@@ -20,8 +20,9 @@ class UserInfoAdmin(ChangeOnlyModelAdmin, admin.ModelAdmin):
20 20
 
21 21
 
22 22
 class UserIntegralIncomeExpensesInfoAdmin(ChangeOnlyModelAdmin, admin.ModelAdmin):
23
-    list_display = ('user_id', 'model_id', 'model_name', 'code', 'integral', 'remark', 'updated_at', 'created_at')
24
-    search_fields = ('user_id',)
23
+    list_display = ('user_id', 'brand_id', 'brand_name', 'model_id', 'model_name', 'code', 'integral_from', 'integral', 'final_integral', 'remark', 'updated_at', 'created_at')
24
+    list_filter = ('integral_from', 'status')
25
+    search_fields = ('user_id', )
25 26
 
26 27
 
27 28
 admin.site.register(UserInfo, UserInfoAdmin)

+ 19 - 0
account/migrations/0055_userintegralincomeexpensesinfo_final_integral.py

@@ -0,0 +1,19 @@
1
+# -*- coding: utf-8 -*-
2
+# Generated by Django 3.2.16 on 2022-10-27 10:07
3
+
4
+from django.db import migrations, models
5
+
6
+
7
+class Migration(migrations.Migration):
8
+
9
+    dependencies = [
10
+        ('account', '0054_userinfo_coupon_expire_at'),
11
+    ]
12
+
13
+    operations = [
14
+        migrations.AddField(
15
+            model_name='userintegralincomeexpensesinfo',
16
+            name='final_integral',
17
+            field=models.IntegerField(default=0, help_text='最终积分', verbose_name='final_integral'),
18
+        ),
19
+    ]

+ 2 - 2
account/models.py

@@ -343,14 +343,14 @@ class UserIntegralIncomeExpensesInfo(BaseModelMixin):
343 343
     brand_id = models.CharField(_(u'brand_id'), max_length=32, blank=True, null=True, help_text=u'品牌唯一标识', db_index=True)
344 344
     brand_name = models.CharField(_(u'brand_name'), max_length=255, blank=True, null=True, help_text=u'品牌名称')
345 345
 
346
-    integral_from = models.IntegerField(_(u'integral_from'), choices=INTEGRAL_FROM, default=PRODUCT, help_text=u'积分来源')
347
-
348 346
     model_id = models.CharField(_(u'model_id'), max_length=32, blank=True, null=True, help_text=u'型号唯一标识', db_index=True)
349 347
     model_name = models.CharField(_(u'model_name'), max_length=255, blank=True, null=True, help_text=u'型号名称')
350 348
 
351 349
     code = models.CharField(_(u'code'), max_length=32, blank=True, null=True, help_text=u'机身码', db_index=True)
352 350
 
351
+    integral_from = models.IntegerField(_(u'integral_from'), choices=INTEGRAL_FROM, default=PRODUCT, help_text=u'积分来源')
353 352
     integral = models.IntegerField(_(u'integral'), default=0, help_text=u'增减积分')
353
+    final_integral = models.IntegerField(_(u'final_integral'), default=0, help_text=u'最终积分')
354 354
 
355 355
     remark = models.CharField(_(u'remark'), max_length=255, blank=True, null=True, help_text=u'备注')
356 356